
#include "SQLNCharExpr.h"

#include "../../visitor/SQLASTVisitor.h"
#include "../../../utils/StringUtils.h"

SQLNCharExpr::SQLNCharExpr()
{
}

SQLNCharExpr::~SQLNCharExpr()
{
}

SQLNCharExpr::SQLNCharExpr(string_ptr theText)
    : super(theText)
{
  // super(theText);
}

SQLNCharExpr::SQLNCharExpr(string_ptr text, SQLObject_ptr parent)
{
  this->text = text;
  this->parent = parent;
}

void SQLNCharExpr::output(std::stringstream * buf)
{
  if ((*text == "") || (text->length() == 0))
  {
    (*buf)<<"NULL";
    return;
  }

  (*buf)<<"N'";
  // buf.append(this.text.replaceAll("'", "''"));
  text = StringUtils::replaceAll(text, make_string_ptr("'"), make_string_ptr("''"));
  (*buf)<<*text;
  (*buf)<<"'";

  // buf.append("'");
}

void SQLNCharExpr::accept0(SQLASTVisitor_ptr visitor)
{
  visitor->visit(SharedObject(SQLNCharExpr));
  visitor->endVisit(SharedObject(SQLNCharExpr));
}

SQLObject_ptr SQLNCharExpr::clone()
{
  SQLObject_ptr clone_tmp = SQLNCharExpr_ptr(new SQLNCharExpr());
  SQLNCharExpr_ptr clone_res = std::dynamic_pointer_cast<SQLNCharExpr>(clone_tmp);

  return clone_res;
}